﻿Imports DevComponents.DotNetBar

Public Class ucCapnhatDanhmucsp

    Event Closed(sender As Object)

    Private eActive As mdQuanLyBanHang.ActionType
    Private dtrow As DataGridViewRow
    Private dmspBUS As New CategoriesBUS()

    Public _isCancelled As Boolean = True
    Public Property Cancelled() As Boolean
        Get
            Return _isCancelled
        End Get
        Private Set(ByVal value As Boolean)
            If value <> _isCancelled Then
                _isCancelled = value
            End If
        End Set
    End Property

    Private Sub ButtonItemThoat_Click(sender As Object, e As EventArgs) Handles ButtonItemThoat.Click
        'SuperValidator1.Enabled = False

        Dim parent = DirectCast(Application.OpenForms.Item(0), MetroAppForm)
        parent.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Right)
    End Sub

    Private Sub ButtonItemSave_Click(sender As Object, e As EventArgs) Handles ButtonItemSave.Click
        BalloonTip1.SetBalloonCaption(ItemPanel1, "Thông báo")
        If ValidateData() Then
            'MessageBoxEx.Show("true", "test", MessageBoxButtons.OK)
            If eActive = ActionType.AddRecord Then
                dmspBUS.Categories_Insert(txtTendanhmuc.Text, txtMota.Text, Date.Now, "modiby", Date.Now, "createby", False)
                BalloonTip1.SetBalloonText(ItemPanel1, "Thêm danh mục " + txtTendanhmuc.Text + " thành công")
            ElseIf eActive = ActionType.EditRecord Then
                dmspBUS.Categories_Update(Integer.Parse(dtrow.Cells(0).Value), txtTendanhmuc.Text, txtMota.Text, Date.Now, "modiby", Date.Parse(dtrow.Cells(3).Value), "createby", False)
                BalloonTip1.SetBalloonText(ItemPanel1, "Cập nhật danh mục " + txtTendanhmuc.Text + " thành công")
            End If
            BalloonTip1.ShowBalloon(ItemPanel1)
            RaiseEvent Closed(Me)
        Else
            'MessageBoxEx.Show("false", "test", MessageBoxButtons.OK)
        End If
    End Sub

    Private Function ValidateData() As Boolean
        Dim validate As Boolean = True
        If txtTendanhmuc.Text = "" Then
            validate = False
            ErrorProvider1.SetError(txtTendanhmuc, "Vui lòng nhập tên nhà sản xuất")
        Else
            ErrorProvider1.SetError(txtTendanhmuc, "")
        End If
        Return validate
    End Function

    Public Sub New(ByVal eAct As Integer, _
                   ByVal _dtrow As DataGridViewRow)
        MyBase.New()
        ' This call is required by the designer.
        InitializeComponent()
        eActive = eAct
        dtrow = _dtrow
        If eActive = ActionType.AddRecord Then
            lbTieude.Text = "Thêm danh mục sản phẩm mới"
        ElseIf eActive = ActionType.EditRecord Then
            lbTieude.Text = "Cập nhật danh mục sản phẩm"
            txtTendanhmuc.Text = dtrow.Cells(1).Value.ToString()
            txtMota.Text = dtrow.Cells(2).Value.ToString()
        End If


        ' Add any initialization after the InitializeComponent() call.

    End Sub
End Class
